package com.cfets.annualAssessment.service;

import com.cfets.annualAssessment.entity.CfetsPlanet;
import com.cfets.annualAssessment.entity.PlanetToken;
import com.cfets.annualAssessment.mapper.CfetsPicsMapper;
import com.cfets.annualAssessment.mapper.CfetsPlanetMapper;
import com.cfets.annualAssessment.mapper.PlanetTokenMapper;
import com.cfets.annualAssessment.util.CheckUtil;
import com.sun.org.apache.xml.internal.utils.CharKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.method.P;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.common.base.select.SelectByPrimaryKeyMapper;
import tk.mybatis.mapper.entity.Example;

import javax.swing.plaf.PanelUI;
import java.util.List;

/**
 * @author DavidSun
 * @create 2019-02-22 10:39
 * @desc 交易星球的服务
 **/
@Service
public class CfetsPlanetService   {
    @Autowired
    private CfetsPlanetMapper cfetsPlanetMapper;

    @Autowired
    private PlanetTokenMapper planetTokenMapper;



    /*
    *
    * public List<GameSe> getVIPLogin(GameSe gameSe) {
        Example example=new Example(GameSe.class);
        Example.Criteria criteria =example.createCriteria();
        if (!StringUtils.isEmpty(gameSe.getOrg_name())) {
            criteria.andEqualTo("org_name",gameSe.getOrg_name());
        }
        if(!StringUtils.isEmpty(gameSe.getName())){
            criteria.andEqualTo("name",gameSe.getName());
        }
//        criteria.andEqualTo("is_sign",0);
        return gameScoreMapper.selectByExample(example);
    }
    *
    *
    * */

    /*
    * public boolean newGameSit(Gamesit gamesit) {
        return gameSitMapper.insertSelective(gamesit)>0;
    }
     public boolean HaveSign (GameSe gameSe) {
        gameSe.setIs_sign(1);
        return gameScoreMapper.updateByPrimaryKey(gameSe)>0;
    }


    * */



    public  boolean HaveSign(CfetsPlanet cfetsPlanet){
        return  cfetsPlanetMapper.updateByPrimaryKey(cfetsPlanet)>0;
    }

    public boolean newPlanetToken(PlanetToken planetToken){
        return  planetTokenMapper.insertSelective(planetToken)>0;
    }




    // 根据姓名和身份证来获取此人所有的数据
    public  List<CfetsPlanet> getPlantLogin(CfetsPlanet cfetsPlanet){
        Example example = new Example(CfetsPlanet.class);
        Example.Criteria criteria = example.createCriteria();
        if (!StringUtils.isEmpty(cfetsPlanet.getName())){
            criteria.andEqualTo("name",cfetsPlanet.getName());
        }
        if (!StringUtils.isEmpty(cfetsPlanet.getUserid())){
            criteria.andEqualTo("userid",cfetsPlanet.getUserid());
        }
        return cfetsPlanetMapper.selectByExample(example);
    }



    // 根据token获取数据交易星球数据


    public CfetsPlanet getPlanetMessagesByToken (String token) {
        Example example = new Example(PlanetToken.class);
        Example.Criteria criteria = example.createCriteria();
        CfetsPlanet cfetsPlanet = new CfetsPlanet();
        if (!StringUtils.isEmpty(token)) {
            criteria.andEqualTo("tokenid", token);
        }
        List<PlanetToken> planetTokenList = planetTokenMapper.selectByExample(example);

        return  cfetsPlanetMapper.selectByPrimaryKey(planetTokenList.get(0).getUserid());

    }

    // 获取所有数据
    public List<CfetsPlanet> getAllPlanets(CfetsPlanet cfetsPlanet){
        Example example = new Example(CfetsPlanet.class);
        Example.Criteria  criteria =  example.createCriteria();
        if (!CheckUtil.isEmpty(cfetsPlanet.getName())){
            criteria.andLike("name","%"+cfetsPlanet.getName()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getUserid())){
            criteria.andLike("userid","%"+cfetsPlanet.getUserid()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getUsname())){
            criteria.andLike("usname","%"+cfetsPlanet.getUsname()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getStory())){
            criteria.andLike("story","%"+cfetsPlanet.getStory()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getRanking())){
            criteria.andLike("ranking","%"+cfetsPlanet.getRanking()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getPass())){
            criteria.andLike("passs","%"+cfetsPlanet.getPass()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getUserkind())){
            criteria.andLike("userkind","%"+cfetsPlanet.getUserkind()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getBusyday())){
            criteria.andLike("busyday","%"+cfetsPlanet.getBusyday()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getMostcount())){
            criteria.andLike("mostcount","%"+cfetsPlanet.getMostcount()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getCounter())){
            criteria.andLike("counter","%"+cfetsPlanet.getCounter()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getMcounter())){
            criteria.andLike("mcounter","%"+cfetsPlanet.getMcounter()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getWcounter())){
            criteria.andLike("wcounter","%"+cfetsPlanet.getWcounter()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getStars())){
            criteria.andLike("stars","%"+cfetsPlanet.getStars()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getSamestars())){
            criteria.andLike("samestars","%"+cfetsPlanet.getSamestars()+"%");
        }
        if (!CheckUtil.isEmpty(cfetsPlanet.getImageurl())){
            criteria.andLike("imageulr","%"+cfetsPlanet.getImageurl()+"%");
        }

        return cfetsPlanetMapper.selectByExample(example);


    }
}
